package io.ticktick.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.ticktick.modules.app.annotation.Login;
import io.ticktick.modules.app.entity.ChatMemberEntity;
import io.ticktick.modules.app.service.ChatMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.ticktick.modules.app.entity.GroupChatEntity;
import io.ticktick.modules.app.service.GroupChatService;
import io.ticktick.common.utils.R;



/**
 * 群聊信息
 *
 * @author hwf
 * @email zhongku0225@gmail.com
 * @date 2019-11-13 17:15:19
 */
@RestController
@RequestMapping("app/groupchat")
public class GroupChatController {
    @Autowired
    private GroupChatService groupChatService;

    /**
     * 列表
     */
    @Login
    @GetMapping("/list/{userId}")
    public R list(@PathVariable("userId") Long userId){
        List<GroupChatEntity> list = groupChatService.getGroupChatByUserId(userId);
        return R.ok().put("groupChat", list);
    }

    /**
     * 信息
     */
    @Login
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		GroupChatEntity groupChat = groupChatService.getById(id);

		if(groupChat != null)
		    return R.ok("没有该信息");

        return R.ok().put("groupChat", groupChat);
    }

    /**
     * 保存
     */
    @Login
    @PostMapping("/save")
    public R save(@RequestBody GroupChatEntity groupChat){
		groupChatService.save(groupChat);

        return R.ok();
    }

    /**
     * 修改
     */
    @Login
    @PostMapping("/update")
    public R update(@RequestBody GroupChatEntity groupChat){
		groupChatService.updateById(groupChat);

        return R.ok();
    }

    /**
     * 删除
     */
    @Login
    @GetMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		groupChatService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
